package Shared;

/**
 * Object representing a radio message
 */

public class RadioMessage {

	private MapPosition position;
	private int ambulanceID;
	private AmbType ambulanceType;
	private MsgType type;

	/**
	 * Creates a radio message of type "messageType" for or from ambulance with
	 * ID "ambulanceID".
	 * 
	 * @param messageType
	 *            the message type
	 * @param ambulanceID
	 *            the ambulance ID
	 */
	public RadioMessage(MsgType messageType, int ambulanceID) {
		this.type = messageType;
		this.ambulanceID = ambulanceID;
	}

	/**
	 * Creates a radio message of type "messageType" for or from ambulance with
	 * ID "ambulanceID" and amublance type "ambulanceType".
	 * 
	 * @param messageType
	 *            the message type
	 * @param ambulanceID
	 *            the ambulance ID
	 * @param ambulanceType
	 *            the ambulance type
	 */
	public RadioMessage(MsgType messageType, int ambulanceID, AmbType ambulanceType) {
		this.type = messageType;
		this.ambulanceID = ambulanceID;
		this.ambulanceType = ambulanceType;
	}

	/**
	 * Creates a radio message of type Position for or from ambulance with ID
	 * "ambulanceID" and with position to communicate "position".
	 * 
	 * @param position
	 *            the position to communicate
	 * @param ambulanceID
	 *            the ambulance ID
	 */
	public RadioMessage(MapPosition position, int ambulanceID) {
		this.position = position;
		this.type = MsgType.POSITION;
		this.ambulanceID = ambulanceID;
	}

	/**
	 * 
	 * @return the message type
	 */
	public MsgType getType() {
		return this.type;
	}

	/**
	 * 
	 * @return the id of the ambulance sending or receiving the message
	 */
	public int getAmbID() {
		return this.ambulanceID;
	}

	/**
	 * PRE : ambulanceType != null : the adequate constructor had to be used for
	 * this function to be called.
	 * 
	 * @return the ambulance type of the ambulance sending or receiving the
	 *         message
	 */
	public AmbType getAmbType() {
		assert ambulanceType != null;
		return this.ambulanceType;
	}

	public MapPosition getPosition() {
		assert this.type == MsgType.POSITION && this.position != null;
		return this.position;
	}

	@Override
	public String toString() {
		return "MSG (" + type + ")  from (" + ambulanceID + ")  at (" + position + ")";
	}
}
